import { fetchResearchGroupById } from "@/api/research-group";

/**
 * @param {Number} userId
 * @param {Number} ownerId
 * @param {Number} groupId
 * @returns {Boolean}
 * @example see @/views/permission/directive.vue
 */
export function checkInProject(userId, ownerId, groupId) {
    if (userId === ownerId) {
        return true;
    } else {
        fetchResearchGroupById(groupId)
        .then((res) => {
            const members = res.data[0].researchGroupMembers?.length > 0
                ? JSON.parse(res.data[0].researchGroupMembers)
                : [];
            members.forEach(element => {
                if (userId === element.id) {
                    return true;
                }
            });
            
        })
        .catch((err) => {
            console.log(err);
        });
        return false;
    }
  }